package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Api(tags = "店铺管理")
@Slf4j
@RequestMapping("/admin/shop")
public class ShopController {
    private static final String SHOP_STATUS = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("设置店铺营业状态")
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable String status){
        log.info("设置店铺营业状态：{}",status.equals("1")?"营业":"休息");
        redisTemplate.opsForValue().set(SHOP_STATUS,Integer.parseInt(status));
        return Result.success();
    }

    @ApiOperation("商家获取店铺营业状态")
    @GetMapping("/status")
    public Result getShopStatus(){
        String status = String.valueOf(redisTemplate.opsForValue().get(SHOP_STATUS));
        log.info("商家获取店铺营业状态：{}",status.equals("1")?"营业":"休息");
        return Result.success(Integer.parseInt(status));
    }
}
